﻿/* Copyright 2007-2008 dnAnalytics Project.
 *
 * Contributors to this file:
 * Patrick van der Velde
 * Marcus Cuda - http://marcus.cuda.net
 *
 * This file is part of dnAnalytics.  dnAnalytics is licensed under the 
 * Microsoft Public License. See License.txt for a complete copy of the
 * license.
 */

namespace dnAnalytics.LinearAlgebra.Decomposition
{
    internal class DenseCholesky : AbstractCholesky
    {
        public DenseCholesky(Matrix matrix) : base(matrix) {}

        protected override bool DoCompute(Matrix matrix, int order)
        {
            int info = SafeNativeMethods.d_cholesky_factor(matrix.Rows, ((DenseMatrix) matrix).Data);
            return info == 0;
        }

        protected override void DoSolve(Matrix factor, Matrix result)
        {
            SafeNativeMethods.d_cholesky_solve(factor.Rows, result.Columns, ((DenseMatrix)factor).Data, ((DenseMatrix)result).Data);
        }

        protected override void DoSolve(Matrix factor, Vector result)
        {
            SafeNativeMethods.d_cholesky_solve(factor.Rows, 1, ((DenseMatrix)factor).Data, ((DenseVector)result).Data);
        }
    }
}